package jp.co.jbuy.product;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

public class ProductDetailView{
	private ProductDetail productDetail;
	
	public ProductDetailView(ProductDetail productDetail){
		this.productDetail = productDetail;
	}
	
	public String getStrStartTime(){
		SimpleDateFormat sdf = new SimpleDateFormat("MM月 dd日 HH時 mm分");
		return sdf.format(this.productDetail.getStartTime());
	}
	
	public String getStrEndTime(){
		SimpleDateFormat sdf = new SimpleDateFormat("MM月 dd日 HH時 mm分");
		return sdf.format(this.productDetail.getEndTime());
	}
	
	public String getRemainTime(){
		long remain = 0;
		if(this.productDetail.getEndTime() != null){
			remain = this.productDetail.getEndTime().getTime() 
					- Calendar.getInstance(TimeZone.getTimeZone("GMT+9")).getTimeInMillis();
			remain = remain / 1000;
		}
		
		if(remain/(24*3600) > 0){
			return "" + remain/(24*3600) + "日";
		}else if(remain/3600 > 0){
			return "" + remain/3600 + "時";
		}else if(remain/60 > 0){
			return "" + remain/60 + "分";
		}else if(remain > 0){
			return "" + remain + "秒";
		}else{
			return "オークション終了";
		}
	}
	
	public Transactor getHighestBidder1(){
		Transactor bidder1 = null;
		if(this.productDetail.getHighestBidderList() != null 
				&& this.productDetail.getHighestBidderList().size() > 0){
			bidder1 = this.productDetail.getHighestBidderList().get(0);
		}
		return bidder1;
	}
	
}
